import  redis.clients.jedis.Jedis;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class RedisUtil {
    private static JedisPool jedisPool;

    static {
        Properties props = new Properties();
        InputStream is = RedisUtil.class.getClassLoader().getResourceAsStream("redis.properties");
        try {
            props.load(is);
        } catch (IOException e) {
            e.printStackTrace();
        }
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        jedisPoolConfig.setMaxTotal(Integer.valueOf(props.getProperty("redis.pool.maxTotal")));
        jedisPoolConfig.setMaxIdle(Integer.valueOf(props.getProperty("redis.pool.maxIdle")));
        jedisPoolConfig.setMinIdle(Integer.valueOf(props.getProperty("redis.pool.minIdle")));
        jedisPoolConfig.setMaxWaitMillis(Long.valueOf(props.getProperty("redis.pool.maxWaitMillis")));
        jedisPool = new JedisPool(jedisPoolConfig, props.getProperty("redis.host"), Integer.valueOf(props.getProperty("redis.port")), 5000, props.getProperty("redis.password"));
    }

    public static Jedis getJedis() {
        return jedisPool.getResource();
    }
}
